package engine.light;

import java.nio.FloatBuffer;

import org.lwjgl.BufferUtils;

import static org.lwjgl.opengl.GL11.*;

public class SpotLight extends PointLight {
	
	private FloatBuffer spotDirection;
	
	private float spotCutoff;
	private float spotExponent;
	
	public SpotLight() {
		super();
		
		spotDirection = BufferUtils.createFloatBuffer(3);
	}
	
	public FloatBuffer getSpotDirection() {
		return spotDirection;
	}
	
	public void setSpotDirection(float x, float y, float z) {
		spotDirection.put(0, x);
		spotDirection.put(1, y);
		spotDirection.put(2, z);
	}

	public float getSpotCutoff() {
		return spotCutoff;
	}

	public void setSpotCutoff(float spotCutoff) {
		this.spotCutoff = spotCutoff;
	}

	public float getSpotExponent() {
		return spotExponent;
	}

	public void setSpotExponent(float spotExponent) {
		this.spotExponent = spotExponent;
	}
	
	@Override
	public void apply(int lightSource) {
		super.apply(lightSource);
		
		spotDirection.rewind();
		
		glLight(lightSource, GL_SPOT_DIRECTION, spotDirection);
		glLightf(lightSource, GL_SPOT_EXPONENT, spotExponent);
		glLightf(lightSource, GL_SPOT_CUTOFF, spotCutoff);
	}
}
